<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
</body>
<script>
  ;(function(){
    var Compute = function Compute(obj){
      this.x = obj.firstNum || 0;
      this.y = obj.secimdNum || 0;
    }
    Compute.prototype = {
      push: function(){
        console.log(this.x + this.y);
      },
      minus: function(){
        console.log(this.x - this.y);
      },
      cheng: function(){
        console.log(this.x * this.y);
      },
      chu: function(){
        console.log(this.x / this.y);
      }
    }
    window.Compute = Compute;
  })();

  var compute = new Compute({
    firstNum: 1,
    secimdNum: 2,
  });

  compute.push();
  compute.minus();
  compute.cheng();
  compute.chu();


  (function(){
    var Temp = function Temp(){}
    Temp.prototype = {
      jia: function (a, b) {
        return a + b;
      },
      jian: function (a, b) {
        return a - b;
      },
      chen: function (a, b) {
        return a * b;
      },
      chu: function (a, b) {
        return a / b;
      },
    }
    window.Temp = Temp;
  })();

  let temp = new Temp();
  console.log(temp.jia(4,6));
  console.log(temp.jian(4,6));
  console.log(temp.chen(4,6));
  console.log(temp.chu(4,6));



  // function Professor(){}
  // Professor.prototype = {
  //   name: "MR.Zhang",
  //   tSkill: "JAVA",
  // }
  // var professor = new Professor();
  
  // function Teacher(){
  //   this.name = "Mr.Wang";
  //   this.mSkill = "JS/JQ";
  // }
  // Teacher.prototype = professor;
  // var teacher = new Teacher();
  // console.log(teacher);

  // function Buffet(){};
  // Buffet.prototype = Teacher.prototype;
  // let buffet = new Buffet();

  // function Student(){
  //   this.name = "Mr. li";
  //   this.mSkill = "";
  // }
  // Student.prototype = buffet;
  // Student.prototype.age = 20;
  // let student = new Student();
  // console.log(student);


  // 企业级继承写法
  var inherit = (function(){
    var Buffer = function(){};
    return function(Target, Origin){
      Buffer.prototype = Origin.prototype;
      Target.prototype = new Buffer();
      Target.prototype.constructor = Target;
      Target.prototype.super_class = origin;
    }
  })();

  function Teacher() {};
  Teacher.prototype.name = "Mr. Zhang";
  function Student() {};
  function Buffer() {};
  inherit(Student, Teacher);
  Student.prototype.age = 23;
  var s = new Student();
  var t = new Teacher();
  console.log(s);
  console.log(t);




  // let init = (function(){
  //   let btn = function(){}
  //   return function(ts1, ts2){
  //     btn.prototype = ts2.prototype;
  //     ts1.prototype = new btn();
  //     ts1.prototype.constructor = ts1;
  //   }
  // })()

  // let temps1 = function(){}
  // temps1.prototype.name = "lao shi";
  // let temps2 = function(){}
  
  // init(temps2, temps1);
  // temps2.prototype.age = 18;
  // let ts1 = new temps1();
  // let ts2 = new temps2();
  // console.log(ts1);
  // console.log(ts2);



  //链式操作
  let obj = {
    zao: function(){
      console.log("zao");
      return this;
    },
    zhong: function(){
      console.log("zhong");
      return this;
    },
    wan:function(){
      console.log("wan");
      return this;
    }
  }
  // obj.zao().zhong().wan();
  for(let key in obj){
    console.log(obj[key]);
  }

  function Car(){
    this.brand = "Benz";
    this.color = "block";
    this.displacement = "4.0";
  }
  Car.prototype = {
    lang: 5,
    width: 2.5,
  }

  let car = new Car();
  for(let i in car){
    // console.log(car[i]);
    if(car.hasOwnProperty(i)){
      console.log(car[i]);
    }
  }

 var sum = (function(n){
   if(n <= 1){
     return 1;
   }
   return n + arguments.callee(n - 1);
 })(100);
 console.log(sum);



</script>
</html>